﻿using Abp.Runtime.Session;
using Abp.Timing.Timezone;
using Admin.Application.Custom.ReportForms.Dto;
using Magicodes.Admin.DataExporting.Excel.EpPlus;
using Magicodes.Admin.Dto;
using Magicodes.Admin.Storage;
using System;
using System.Collections.Generic;
using System.Text;

namespace Admin.Application.Custom.ReportForms
{
    public class DaoDaLvReporExcelExporter : EpPlusExcelExporterBase, IDaoDaLvReporExcelExporter
    {
        private readonly ITimeZoneConverter _timeZoneConverter;
        private readonly IAbpSession _abpSession;

        public DaoDaLvReporExcelExporter(
            ITimeZoneConverter timeZoneConverter,
            IAbpSession abpSession,
            ITempFileCacheManager tempFileCacheManager)
            : base(tempFileCacheManager)
        {
            _timeZoneConverter = timeZoneConverter;
            _abpSession = abpSession;
        }
        public FileDto ExportToFile(List<DaoDaLvListDto> daoDaLvListDtos)
        {
            return CreateExcelPackage(
                "DaoDaLvList.xlsx",
                excelPackage =>
                {
                    var sheet = excelPackage.Workbook.Worksheets.Add(L("DaoDaLvs"));
                    sheet.OutLineApplyStyle = true;

                    AddHeader(
                        sheet,
                        L("发运日期"),
                        L("运单号"),
                        L("发货号"),
                        L("省份"),
                        L("服务站代码"),
                        L("收货单位"),
                        L("收件地址"),
                        L("联系电话"),
                        L("箱数"),
                        L("重量"),


                        L("合计重量"),
                        L("体积重量"),
                        L("面单金额"),
                        L("结算金额"),
                        L("是否妥投"),
                        L("签收时间"),
                        L("签收人"),
                        L("要求到达时限"),
                        L("实际到达时限"),
                        L("是否超时")
                        );

                    AddObjects(
                        sheet, 2, daoDaLvListDtos,
                        _ => _.StartDate,
                        _ => _.waybillNo,
                        _ => _.ShippingNumber,
                        _ => _.Province,
                        _ => _.ServiceStationCode,
                        _ => _.ServiceStationName,
                        _ => _.ReceiverAddress ,

                          _ => _.ContactPhoneNumber, 
                            _ => _.NumberOfCases, 
                              _ => _.Weight,

                            _ => "",
                            _ => "",
                            _ => _.SettlementAmount,
                            _ => _.IsDeliverText,
                            _ => _.ToSignForTheTime,
                            _ => _.Signer,
                            _ => _.LimitDay,
                            _ => _.ActualTimeOfArrival,
                            _ => _.IsTimeoutText 

                        
                        );

                    //Formatting cells

                    var lastLoginTimeColumn = sheet.Column(8);
                    lastLoginTimeColumn.Style.Numberformat.Format = "yyyy-mm-dd";

                    var creationTimeColumn = sheet.Column(10);
                    creationTimeColumn.Style.Numberformat.Format = "yyyy-mm-dd";

                    for (var i = 1; i <= 10; i++)
                    {
                        sheet.Column(i).AutoFit();
                    }
                });
        }
    }
}
